import {resolve} from 'path';
import {defineConfig} from 'vite';
import {VitePluginNode} from 'vite-plugin-node';


const CWD_PATH = process.cwd();
const resolveApp = (...paths) => resolve(CWD_PATH, ...paths);
const ENTRY = resolveApp('./src/index.ts');
const OUT_DIR = resolve('./dist/server');


export default defineConfig({
    resolve: {
        extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json', '.ejs'],
        alias: [
            {find: /^@\/(.*)$/, replacement: resolve(__dirname, './src/$1')}
        ]
    },
    build: {
        lib: {
            entry: ENTRY,
            formats: ['cjs'],
            fileName: '[name].js'
        },
        outDir: OUT_DIR
    },
    plugins: [
        ...VitePluginNode({
            appPath: ENTRY
        })
    ]
});
